<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-tovip-edit"
			th:object="${tovip}">
			<input id="tovipId" name="tovipId" th:field="*{tovipId}"
				type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">服务类型名称：</label>
				<div class="col-sm-8">
					<input id="tovipName" name="tovipName" th:field="*{tovipName}"
						class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">会员卡类型价格：</label>
				<div class="col-sm-8">
					<input id="tovipPrice" name="tovipPrice" th:field="*{tovipPrice}"
						class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">会员卡类型折扣：</label>
				<div class="col-sm-8">
					<input id="tovipDisc" name="tovipDisc" th:field="*{tovipDisc}"
						class="form-control" type="text">
				</div>
			</div>

			<!-- <div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
				</div>
			</div> -->

		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		
		$("#form-tovip-edit").validate({
			rules:{
				tovipName:{
					required:true,
					remote: {
		                url: "/tovip/checkTovipNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
							"tovipId": function() {
							    return $("#tovipId").val();
							},
		                	"tovipName" : function() {
		                		return $.common.trim($("#tovipName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				tovipPrice : {
					required : true,
					checkMoney : true
				},
				tovipDisc : {
					required : true,
					checkDisc : true
				}
			},
			messages: {
		        "tovipName": {
		            remote: "会员卡类型已经存在"
		        }
		    }
		});
		$.validator.addMethod(
				"checkDisc",
				function(value, element, params) {
					var checkDisc = /^0\.[0-9]{1,2}$|^0{1}$|^1{1}$|^1\.[0]{1,2}$/;
					return this.optional(element) || (checkDisc.test(value)); 
					}, "请输入正确的折扣价格"

		);
		$.validator.addMethod(
				"checkMoney",
				function(value, element, params) {
							var checkMoney = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
							return this.optional(element) || (checkMoney.test(value)); 
							}, "请输入正确的金钱格式"

		);
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save("/tovip/edit", $('#form-tovip-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
